Expand description
This crate provides even faster functions for printing integers with decimal format than itoa crate.
If you want to write integers in decimal format to String
, Vec
or any other
contiguous buffer, then this crate is the best choice.
If you want to write integers to a std::io::Write
or std::fmt::Write
,
itoa crate and itoap
crate shows almost same
performance.
The implementation is based on the sse2
algorithm from
itoa-benchmark repository.
While itoa
crate writes integers from last digits, this algorithm writes
from first digits. It allows integers to be written directly to the buffer.
That’s why itoap
is faster than itoa
.
§Feature Flags
alloc
: use alloc crate (enabled by default)std
: use std crate (enabled by default)simd
: use SIMD intrinsics if available
§Examples
let value = 17u64;
let mut buf = String::new();
buf.push_str("value: ");
itoap::write_to_string(&mut buf, value);
assert_eq!(buf, "value: 17");
use core::mem::{MaybeUninit, transmute};
use itoap::Integer;
unsafe {
let mut buf = [MaybeUninit::<u8>::uninit(); i32::MAX_LEN];
let len = itoap::write_to_ptr(buf.as_mut_ptr() as *mut u8, -2953);
let result: &[u8] = transmute(&buf[..len]);
assert_eq!(result, b"-2953");
}
Traits§
- An integer that can be written to pointer.
Functions§
- Write integer to an
fmt::Write
- write
std
Write integer to anio::Write
- Write integer to the buffer pointer directly.
- write_
to_ string alloc
Write integer toString
. - write_
to_ vec alloc
Write integer toVec<u8>
.